package com.front.web.lvyou_specialty_front;

import com.bootdo.common.utils.R;
import com.bootdo.lvyou_specialty.domain.LvyouSpecialtyProductArticle;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/f/productArticleController")
public class ProductArticleFrontController extends LvyouSpecialtySuperController {
    /**
     * 根据分类查看商品推文
     * http://localhost/f/productArticleController/getProductArticleByType
     * @param typeId
     * @return
     */
    @RequestMapping("getProductArticleByType")
    public R getProductArticleByType(@RequestParam(value = "typeId", defaultValue = "0")Long typeId,
                                     @RequestParam(value = "pageNo", defaultValue = "1")Integer pageNo,
                                     @RequestParam(value = "pageSize", defaultValue = "15")Integer pageSize) {
        Map<String, Object> param = getPageNo(pageNo, pageSize);
        param.put("typeId", typeId);

        return R.ok().put("l", lvyouSpecialtyProductArticleService.getByTypeId(param));
    }

    /**
     * 得到推文详情
     * http://localhost/f/productArticleController/getProductArticleDetail
     * @param id
     * @return
     */
    @RequestMapping("getProductArticleDetail")
    public R getProductArticleDetail(@RequestParam("id")Long id) {
        LvyouSpecialtyProductArticle productArticle = lvyouSpecialtyProductArticleService.get(id);
        if (productArticle == null || productArticle.getIsShow() == null || productArticle.getIsShow() == 2) {
            return R.error();
        }
        return R.ok().put("i", productArticle);
    }

}
